package com.rxjava;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;

/**
 * Created by kkmike999 on 16/6/13.
 */
public class Error {
	public static void main(String[] args) {
		Observable.<String>error(new RuntimeException("!!!!!"))
				.doOnError(new Action1<Throwable>() {
					@Override
					public void call(Throwable throwable) {
						System.out.println(throwable.getMessage());
					}
				})
				.onErrorReturn(new Func1<Throwable, String>() {
					@Override
					public String call(Throwable throwable) {
						System.out.println("onErrorReturn");
						return "onErrorReturn";
					}
				})
//				.onErrorResumeNext(new Func1<Throwable, Observable<? extends String>>() {
//					@Override
//					public Observable<? extends String> call(Throwable throwable) {
//						System.out.println("onErrorResumeNext");
//						return Observable.just("onErrorResumeNext");
//					}
//				})
				.subscribe(new Subscriber<String>() {
					@Override
					public void onCompleted() {
						System.out.println("onCompleted");
					}

					@Override
					public void onError(Throwable throwable) {
						System.out.println("onError");
					}

					@Override
					public void onNext(String s) {
						System.out.println("onNext");
					}
				});
	}
}
